﻿using UnityEngine;

namespace Framework.DataTable
{
    public interface IDataParser
    {
        string GetTypeName();
        //0:T DeserializeObject(string) 1:Encode(T,ByteArray) 2:T Decode(ByteArray)
        string[] GetStaticMethodNames();
    }

    internal class Vector3ParseSample : IDataParser
    {
        public static Vector3 Parse(string value)
        {
            var v3 = new Vector3();
            if (string.IsNullOrEmpty(value)) return v3;
            var lst = Framework.Utils.Parse.ParseList(value);
            var len = lst.Length;
            if (len > 0)
            {
                v3.x = float.Parse(lst[0]);
            }
            if (len > 1)
            {
                v3.y = float.Parse(lst[1]);
            }
            if (len > 2)
            {
                v3.z = float.Parse(lst[2]);
            }
            return v3;
        }
        public static void Encode(Vector3 value, ByteArray buffer)
        {
            buffer.Write(value.x);
            buffer.Write(value.x);
            buffer.Write(value.x);
        }
        public static Vector3 Decode(ByteArray buffer)
        {
            var v3 = new Vector3();
            v3.x = buffer.ReadFloat();
            v3.y = buffer.ReadFloat();
            v3.z = buffer.ReadFloat();
            return v3;
        }

        public string GetTypeName()
        {
            return typeof(Vector3).FullName;
        }
        public string[] GetStaticMethodNames()
        {
            return new string[] { nameof(Parse), nameof(Encode), nameof(Decode) };
        }
    }
}